#app.run(debug=True)
import sys
import os
import platform
import logging
import pymysql
pymysql.install_as_MySQLdb()
from storm.locals import *
basedir = os.path.abspath(os.path.dirname(__file__))

if platform.system() == "Windows":
    logdir=basedir
else:
    logdir="/tmp"

logfile = os.path.join(logdir, "error.log")

file_handler = logging.FileHandler(logfile)
file_handler.setFormatter(
        logging.Formatter(
            "%(asctime)s %(module)s:%(funcName)s:%(levelname)s) - %(message)s"
            )
        )
file_handler.setLevel(logging.DEBUG)

sys.path.append(basedir)

from mysrv import app
application = app
configfile = os.path.join(basedir, "appconfig.py")
if os.path.exists(configfile):
    print "found config file: %s." % configfile
    app.config.from_pyfile(configfile)

app.logger.addHandler(file_handler)
app.logger.setLevel(app.config["LOG_LEVEL"])

if __name__ == "__main__":
    app.run(port=80)
    #from gevent import monkey
    #monkey.patch_all()
    #from gevent.pywsgi import WSGIServer
    #WSGIServer(('', 5000), app).serve_forever()

